import { System } from "../ecs/core/System";
import { ecs_trait, ecs_trait_property } from "../ecs/core/Trait";
import { ECPosition } from "../ecs/ext/components/ECPosition";
// import { ecs_trait } from '../ecs/Trait';

enum TestGroup {
    Group1 = 1
}

@ecs_trait()
class Trait {
    @ecs_trait_property(ECPosition)
    position!: ECPosition;
}

export class TestSystem extends System {

    onStart() {
        console.log('TestSystem start');
    }

    onUpdate(deltaTime: number) {
        this.world.forEach(Trait, (entity, bundle) => {
            // 打印y            
            console.log('TestSystem, entity.id', entity.id, bundle.position.y);

            bundle.position.y -= 10;    

            if (bundle.position.y < 0) {
                console.log('TestSystem 销毁entity', entity.id);
                entity.destroy();

                // group count
                let g1 = this.world.getGroup(TestGroup.Group1);
                if (g1) {
                    console.log('TestSystem 销毁后group1 count', g1.getCount());
                }
            }

            // var entity3 = this.world.entityManager.getEntity(3);
            // if (entity3) {

            //     console.log('TestSystem 销毁entity', entity3.id);

            //     console.log('TestSystem 销毁前entityCount', this.world.entityManager.entityCount);
                
            //     // 销毁entity
            //     entity3.destroy();

            //     console.log('TestSystem 销毁后entityCount', this.world.entityManager.entityCount);
            // }
            
        });
    }
}